﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media;

namespace CPPEI.Coolzon.UI
{
    public class DockLayout : Layout
    {
        private DockPanel _panel;
        private PartFrame _centerFrame;

        public override void AttachToPart(ILayoutContainer container)
        {
            _panel = new DockPanel();
            _panel.LastChildFill = true;
            container.SetLayout(this);
        }

        protected override void OnAddFrame(string position, PartFrame frame)
        {
            if (position.ToUpper() == "TOP")
            {
                _panel.Children.Add(frame);
                DockPanel.SetDock(frame, Dock.Top);
            }
            else if (position.ToUpper() == "LEFT")
            {
                _panel.Children.Add(frame);
                DockPanel.SetDock(frame, Dock.Left);
            }
            else if (position.ToUpper() == "RIGHT")
            {
                _panel.Children.Add(frame);
                DockPanel.SetDock(frame, Dock.Right);
            }
            else if (position.ToUpper() == "BOTTOM")
            {
                _panel.Children.Add(frame);
                DockPanel.SetDock(frame, Dock.Bottom);
            }
            else
            {
                _panel.Children.Add(frame);
                _centerFrame = frame;
            }

            if (_centerFrame != null)
            {
                for (int index = 0; index < _panel.Children.Count; index++)
                {
                    if (_panel.Children[index] == _centerFrame)
                    {
                        _panel.Children.RemoveAt(index);
                    }
                }
                _panel.Children.Add(_centerFrame);
            }
        }

        public override object GetUIContent()
        {
            return _panel;
        }

        public override void AddPart(System.Windows.Point position, Part part)
        {
            throw new NotImplementedException();
        }
    }
}
